package leetcode.helper.tree;

/**
 * @author Administrator
 * @see leetcode.code021.MergeTwoSortedLists.IMergeTwoSortedLists <br>
 *      leetcode.code206.ReverseLinkedList.IReverseLinkedList
 */
public class ListNode {
	public int val;
	public ListNode next;

	public ListNode() {
	}

	public ListNode(int val) {
		this.val = val;
	}

	public ListNode(int val, ListNode next) {
		this.val = val;
		this.next = next;
	}

	public static ListNode set(int[] array) {
		ListNode ln = new ListNode();
		return ln.setArray(array);
	}

	public static ListNode[] set2array(int[][] array) {
		ListNode ln = new ListNode();
		ListNode[] ans = new ListNode[array.length];
		for (int i = 0; i < array.length; i++) {
			ans[i] = ln.setArray(array[i]);
		}
		return ans;
	}

	public ListNode setArray(int[] array) {
		if (array == null || array.length == 0)
			return null;
		ListNode head = new ListNode(array[0]);
		ListNode p = head;
		for (int i = 1; i < array.length; i++) {
			p.next = new ListNode(array[i]);
			p = p.next;
		}
		return head;
	}

	public void printListNode(ListNode o) {
		if (o == null)
			return;
		while (o != null) {
			System.out.print(o.val + ",");
			o = o.next;
		}
	}

	public static void prinArray(ListNode[] o) {
		System.out.print('[');
		for (ListNode ln : o) {
			System.out.print('[');
			while (ln != null) {
				System.out.print(ln.val + ",");
				ln = ln.next;
			}
			System.out.print("],");
		}
		System.out.println("],");
		System.out.println(" ");

	}

}
